<template>
  <view class="preview-container">
    <!-- #ifndef MP-TOUTIAO -->
    <back-nav-bar title="专辑详情"></back-nav-bar>
    <!-- #endif -->

    <view class="album-content">
      <image :src="albumDetail.imgUrl" class="album-cover"></image>
      <view class="album-info">
        <text class="nickname">作者：{{ albumDetail.nickname }}</text>
        <text class="description">详情：{{ albumDetail.description }}</text>
        <text class="score">评分：{{ albumDetail.score }}</text>
      </view>
    </view>
    <view class="picture-list" v-if="albumDetail.pictureList && albumDetail.pictureList.length">
      <text class="list-title">壁纸列表</text>
      <view
        class="picture-item"
        v-for="(pic, index) in albumDetail.pictureList"
        :key="index"
        @click="goPreview(pic.id)"
      >
        <image :src="pic.smallPicurl" mode="aspectFill" class="picture-image"></image>
        <text class="picture-classname">{{ pic.className }}</text>
        <text class="picture-description">{{ pic.description }}</text>
      </view>
    </view>
  </view>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { apiGetAlbumDetail } from '@/api/apis.js'
import BackNavBar from '@/components/back-nav-bar/back-nav-bar.vue'

const albumDetail = ref({})

onLoad(async (e) => {
  try {
    const res = await apiGetAlbumDetail(e.id)
    if (res.code === 200) {
      albumDetail.value = res.data
    } else {
      console.error('获取专辑详情失败:', res.msg)
    }
  } catch (error) {
    console.error('请求错误:', error)
  }
})

const goPreview = (id) => {
  uni.navigateTo({
    url: '/pages/preview/preview?id=' + id,
  })
}

// 返回上一页的方法
const goBack = () => {
  uni.navigateBack({
    delta: 1,
  })
}
</script>

<style lang="scss" scoped>
.preview-container {
  padding: 20px;
  font-family: Arial, sans-serif;
  background-color: #f9f9f9; /* 背景色 */
  border-radius: 10px; /* 圆角 */
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); /* 阴影 */
}

.back-button {
  align-items: center;
  cursor: pointer;
  transition: transform 0.3s;

  text {
    margin-left: 5px;
    font-size: 16px;
    color: #333;
  }
}

.album-content {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  padding: 15px;
  background-color: #fff; /* 专辑背景色 */
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* 阴影 */
  transition: transform 0.3s; /* 动画效果 */

  &:hover {
    transform: scale(1.02); /* 悬停放大效果 */
  }

  .album-cover {
    width: 100px;
    height: 100px;
    border-radius: 8px;
    margin-right: 15px;
    object-fit: cover; /* 确保图片填充且不变形 */
  }

  .album-info {
    flex-grow: 1;

    text {
      display: block;
      margin-bottom: 5px;
    }

    .nickname {
      font-size: 18px;
      color: #333;
      font-weight: bold; /* 加粗作者名 */
    }

    .description {
      font-size: 15px;
      color: #555; /* 变更颜色 */
      line-height: 1.5; /* 行高 */
    }

    .score,
    .views {
      font-size: 14px;
      color: #999;
    }
  }
}

.picture-list {
  margin-top: 20px; /* 与上方内容分隔 */

  .list-title {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 15px;
    color: #444; /* 变更标题颜色 */
  }

  .picture-item {
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    padding: 10px;
    background-color: #fff; /* 照片项背景色 */
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); /* 阴影 */
    transition: background-color 0.3s; /* 动画效果 */

    &:hover {
      background-color: #f1f1f1; /* 悬停背景变化 */
    }

    .picture-image {
      width: 70px; /* 增大图片尺寸 */
      height: 70px;
      border-radius: 8px;
      margin-right: 12px;
      object-fit: cover; /* 确保图片填充且不变形 */
    }

    .picture-classname {
      font-size: 16px;
      color: #333;
      font-weight: bold; /* 字体加粗 */
    }

    .picture-description {
      font-size: 14px;
      color: #777; /* 变更描述颜色 */
    }
  }
}
</style>
